<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    html{
      font-size: 10px;
    }
    .box {
      width: 70px;
      height: 74px;
      background: red;
    }
    .box-rem {
      width: 7rem;
      height: 7.4rem;
      background-color: aqua;
    }
  </style>
</head>
<body>

  <div class="box">box</div>
  <div class="box-rem">box</div>
  <script>
    // 当前设备的宽度
    const clientWidth = document.documentElement.clientWidth;
    // 以iphone6为基准，iphone6的宽度为375px
    const baseWidth = 375;
    // 以iphone6为基准，iphone6的字体大小为10px
    const baseFontSize = 10;
    // 当前设备的字体大小
    const fontSize = clientWidth / baseWidth * baseFontSize;
    // 设置当前设备的字体大小
    document.documentElement.style.fontSize = fontSize + 'px';
  </script>
</body>
</html>

